<?php

session_start();
// checking the session
if (!$_SESSION['username']) {
    header("location:../user/login.php");
}
if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}
if ($_POST['chkDel']) {
    include '../../libraries/dbconfig.php';
  
    $chk = $_POST['chkDel'];
    $rowid = rowid;



    for ($i = 0; $i < count($chk); $i++) {
        if ($chk[$i] != "") {
             $get = mysql_query("select productid,qty from billdetails where billno = '$chk[$i]'");
          while ($get_data = mysql_fetch_array($get)) {
             $productid = $get_data['productid'];
           
            $qty = $get_data['qty'];
             $invoice_update=mysql_query("Update invoicedetails set sold = sold - '$qty'  where productid = '$productid'") or die(mysql_error());
   
        }
         $del = mysql_query("DELETE FROM billdetails WHERE billno = '$chk[$i]'");
          $del2 = mysql_query("DELETE FROM bills WHERE billno = '$chk[$i]'");
        }
    }
      header("location:sales_billing.php?st=1"); 
}
    
    ?>